package com.rwind.dynamic.datasource;

import java.util.Date;
import java.util.List;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.stereotype.Component;


@Component
public class MySmartInitializingSingleton implements SmartInitializingSingleton ,BeanFactoryAware {

	private BeanFactory beanFactory;
	
	//@Autowired
	//private PayinfoDictMapper payinfoDictMapper;
	
	@Override
	public void afterSingletonsInstantiated() {
	/*	PayInfoDictPo query = new PayInfoDictPo();
		query.setCodeType("ACP_DIST_CONF");
		//PayinfoDictMapper payinfoDictMapper = beanFactory.getBean(PayinfoDictMapper.class); 
		List<PayInfoDictPo> list = payinfoDictMapper.selectPayInfoDict(query);*/
		String beanClass = "com.huoli.pasettle.tempbean.DemoBean";
		BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(beanClass);
		builder.addPropertyValue("name", "rwind");
		builder.addPropertyValue("day", new Date());
		DefaultListableBeanFactory defaultBeanFactory = (DefaultListableBeanFactory) beanFactory;
		defaultBeanFactory.registerBeanDefinition("demoBean", builder.getBeanDefinition());
	}

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		 this.beanFactory = beanFactory;
		
	}

}
